﻿-- =============================================
-- Author:		gsj
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Create PROCEDURE [dbo].[proc_Receipt_Cancel]
	(

	@OrderId uniqueidentifier,
	@Id int,

	
	@CancelMemo nvarchar(3000),
	@CancelUserName varchar(20),
	@CancelEName nvarchar(50)
	)
AS
BEGIN

	BEGIN TRANSACTION--开始事务
    DECLARE @errorSun INT --定义错误计数器
    SET @errorSun=0 --没错为0



	update [Receipt] set CancelMemo=@CancelMemo,CancelUserName=@CancelUserName,CancelEName=@CancelEName
          ,flag=1,CancelDate=getdate() where id=@Id
         
        if @@ROWCOUNT<1
		begin
			set @errorSun=@errorSun+1		
			goto e;
		end
	
	update [order] set RCount=RCount-1 where Oid=@OrderId
	
	    if @@ROWCOUNT<1
		begin
			set @errorSun=@errorSun+1		
			goto e;
		end
	
	
	 e:
    PRINT @errorSun
	if @errorSun>0
	begin
		rollback TRANSACTION
	end
	else
	begin

		commit TRANSACTION

	END
	
END
